package com.example.myDesignPatterns.行为型模式.命令模式Command;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class OrderCommand implements Command{
    //持有接受者对象
    private SeniorChef receiver;
    private Order order;
    @Override
    public void execute() {
        System.out.println(order.getDiningTable()+"桌的订单");
        for (String key : order.getFoodDic().keySet()) {
            receiver.makeFood(order.getFoodDic().get(key), key);
        }
        try {
            Thread.sleep(100);//停顿一下 模拟做饭的过程
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(order.getDiningTable() + "桌的饭弄好了");
    }
}

@Data
class Order{
    // 餐桌号码
    private int diningTable;
    // 用来存储餐名并记录份数
    private Map<String, Integer> foodDic = new HashMap<String, Integer>();
}

// 资深大厨类 是命令的Receiver
class SeniorChef {
    public void makeFood(int num,String foodName) {
        System.out.println(num + "份" + foodName);
    }
}